﻿namespace Sidvall.WorkItemManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class WorkItemWorkCondition : global::Sidvall.WorkItemManager.UI.Entities.Core.BusinessBase, global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition
    {
        #region Business Members

        #region ConditionContext

        private string _ConditionContext = string.Empty;
        partial void OnBeforeConditionContextPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeConditionContextPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterConditionContextPropertyChanged();
        public string ConditionContext
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_ConditionContext);
                OnBeforeConditionContextPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _ConditionContext);
                OnBeforeConditionContextPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("ConditionContext", eventData.Value, true, true, true);
                    OnAfterConditionContextPropertyChanged();
                }
            }
        }

        #endregion
        #region GroupId

        private string _GroupId = string.Empty;
        partial void OnBeforeGroupIdPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeGroupIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterGroupIdPropertyChanged();
        public string GroupId
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_GroupId);
                OnBeforeGroupIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _GroupId);
                OnBeforeGroupIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("GroupId", eventData.Value, true, true, true);
                    OnAfterGroupIdPropertyChanged();
                }
            }
        }

        #endregion
        #region InvalidAction

        private global::Sidvall.WorkItemManager.Workflow.ThreadAction _InvalidAction = global::Sidvall.WorkItemManager.Workflow.ThreadAction.ContinueWithNextWorkItem;
        partial void OnBeforeInvalidActionPropertyGet(Sidvall.Business.PropertyEventData<global::Sidvall.WorkItemManager.Workflow.ThreadAction> eventData);
        partial void OnBeforeInvalidActionPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.ThreadAction> eventData);
        partial void OnAfterInvalidActionPropertyChanged();
        public global::Sidvall.WorkItemManager.Workflow.ThreadAction InvalidAction
        {
            get
            {
                Sidvall.Business.PropertyEventData<global::Sidvall.WorkItemManager.Workflow.ThreadAction> eventData = new Sidvall.Business.PropertyEventData<global::Sidvall.WorkItemManager.Workflow.ThreadAction>(_InvalidAction);
                OnBeforeInvalidActionPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.ThreadAction> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.ThreadAction>(value, _InvalidAction);
                OnBeforeInvalidActionPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("InvalidAction", eventData.Value, true, true, true);
                    OnAfterInvalidActionPropertyChanged();
                }
            }
        }

        #endregion
        #region IsEnabled

        private bool _IsEnabled = false;
        partial void OnBeforeIsEnabledPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeIsEnabledPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIsEnabledPropertyChanged();
        public bool IsEnabled
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_IsEnabled);
                OnBeforeIsEnabledPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsEnabled);
                OnBeforeIsEnabledPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("IsEnabled", eventData.Value, true, true, true);
                    OnAfterIsEnabledPropertyChanged();
                }
            }
        }

        #endregion
        #region IsEnabledOnRetry

        private bool _IsEnabledOnRetry = false;
        partial void OnBeforeIsEnabledOnRetryPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeIsEnabledOnRetryPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIsEnabledOnRetryPropertyChanged();
        public bool IsEnabledOnRetry
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_IsEnabledOnRetry);
                OnBeforeIsEnabledOnRetryPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsEnabledOnRetry);
                OnBeforeIsEnabledOnRetryPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("IsEnabledOnRetry", eventData.Value, true, true, true);
                    OnAfterIsEnabledOnRetryPropertyChanged();
                }
            }
        }

        #endregion
        #region WorkConditionId

        private long _WorkConditionId = 0L;
        partial void OnBeforeWorkConditionIdPropertyGet(Sidvall.Business.PropertyEventData<long> eventData);
        partial void OnBeforeWorkConditionIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<long> eventData);
        partial void OnAfterWorkConditionIdPropertyChanged();
        public long WorkConditionId
        {
            get
            {
                Sidvall.Business.PropertyEventData<long> eventData = new Sidvall.Business.PropertyEventData<long>(_WorkConditionId);
                OnBeforeWorkConditionIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<long> eventData = new Sidvall.Business.PropertyChangeEventData<long>(value, _WorkConditionId);
                OnBeforeWorkConditionIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WorkConditionId", eventData.Value, true, true, true);
                    OnAfterWorkConditionIdPropertyChanged();
                }
            }
        }

        #endregion
        #region WorkItemId

        private long _WorkItemId = 0L;
        partial void OnBeforeWorkItemIdPropertyGet(Sidvall.Business.PropertyEventData<long> eventData);
        partial void OnBeforeWorkItemIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<long> eventData);
        partial void OnAfterWorkItemIdPropertyChanged();
        public long WorkItemId
        {
            get
            {
                Sidvall.Business.PropertyEventData<long> eventData = new Sidvall.Business.PropertyEventData<long>(_WorkItemId);
                OnBeforeWorkItemIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<long> eventData = new Sidvall.Business.PropertyChangeEventData<long>(value, _WorkItemId);
                OnBeforeWorkItemIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WorkItemId", eventData.Value, true, true, true);
                    OnAfterWorkItemIdPropertyChanged();
                }
            }
        }

        #endregion
        #region WorkCondition

        private WorkCondition _WorkCondition;
        partial void OnBeforeWorkConditionPropertyChanged(Sidvall.Business.PropertyChangeEventData<WorkCondition> eventData);
        partial void OnAfterWorkConditionPropertyChanged();
        public WorkCondition WorkCondition
        {
            get
            {
                return _WorkCondition;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<WorkCondition> eventData = new Sidvall.Business.PropertyChangeEventData<WorkCondition>(value, _WorkCondition);
                OnBeforeWorkConditionPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WorkCondition", eventData.Value, true, true, false);
                    OnAfterWorkConditionPropertyChanged();
                }
            }
        }

        #endregion
        #region WorkItem

        private WorkItem _WorkItem;
        partial void OnBeforeWorkItemPropertyChanged(Sidvall.Business.PropertyChangeEventData<WorkItem> eventData);
        partial void OnAfterWorkItemPropertyChanged();
        public WorkItem WorkItem
        {
            get
            {
                return _WorkItem;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<WorkItem> eventData = new Sidvall.Business.PropertyChangeEventData<WorkItem>(value, _WorkItem);
                OnBeforeWorkItemPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WorkItem", eventData.Value, true, true, false);
                    OnAfterWorkItemPropertyChanged();
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowIsValid

        public override bool DataRowIsValid(Sidvall.Data.BusinessRuleFilter filter)
        {
            return global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.DataRowIsValid(this, filter);
        }

        #endregion
        #region DataRowStateIsDirty

        public override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.DataRowStateIsDirty(this);
            }
        }

        #endregion

        #region LoadWorkConditionAsync

        public async System.Threading.Tasks.Task<WorkCondition> LoadWorkConditionAsync()
        {
            return await LoadWorkConditionAsync(false, true, null, null, null);
        }
        public async System.Threading.Tasks.Task<WorkCondition> LoadWorkConditionAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.WorkItemManager.Data.Fields.WorkConditionField, global::Sidvall.WorkItemManager.Data.Relations.WorkConditionRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.WorkItemManager.UI.SystemContext.Current.DataPortal.WorkItemWorkConditionManager.LoadWorkConditionAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters);

            return this.WorkCondition;
        }
        public WorkCondition LoadWorkCondition(WorkCondition item)
        {
            LoadInstanceField("WorkCondition", item, true, true, false);
            return item;
        }

        #endregion
        #region LoadWorkItemAsync

        public async System.Threading.Tasks.Task<WorkItem> LoadWorkItemAsync()
        {
            return await LoadWorkItemAsync(false, true, null, null, null);
        }
        public async System.Threading.Tasks.Task<WorkItem> LoadWorkItemAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.WorkItemManager.Data.Fields.WorkItemField, global::Sidvall.WorkItemManager.Data.Relations.WorkItemRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.WorkItemManager.UI.SystemContext.Current.DataPortal.WorkItemWorkConditionManager.LoadWorkItemAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters);

            return this.WorkItem;
        }
        public WorkItem LoadWorkItem(WorkItem item)
        {
            LoadInstanceField("WorkItem", item, true, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.AcceptChanges(this);
        }

        #endregion
        #region Clone

        public WorkItemWorkCondition Clone()
        {
            var copySettings = Sidvall.Data.CopySettings.Clone();
            return Copy(copySettings);
        }

        #endregion
        #region Copy

        public WorkItemWorkCondition Copy()
        {
            return Copy(null);
        }
        public WorkItemWorkCondition Copy(Sidvall.Data.CopySettings copySettings)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(this, copySettings.RowFilter))
                return null;
            var item = new WorkItemWorkCondition();
            Import(item, this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition item)
        {
            Import(item, null);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition item, Sidvall.Data.CopySettings copySettings)
        {
            Import(this, item, copySettings);
        }
        partial void OnAfterImport(WorkItemWorkCondition destination, global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition source, Sidvall.Data.CopySettings copySettings);
        private void Import(WorkItemWorkCondition destination, global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition source, Sidvall.Data.CopySettings copySettings)
        {
            global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.Import(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings);
        }
        partial void OnAfterImport(WorkItemWorkCondition destination, WorkItemWorkCondition source, Sidvall.Data.CopySettings copySettings);
        private void Import(WorkItemWorkCondition destination, WorkItemWorkCondition source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source as global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition, copySettings);
            OnAfterImport(destination, source, copySettings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<WorkItemWorkCondition> SaveItemAsync()
        {
            return await global::Sidvall.WorkItemManager.UI.SystemContext.Current.DataPortal.WorkItemWorkConditionManager.SaveItemAsync(this);
        }
        public async System.Threading.Tasks.Task<WorkItemWorkCondition> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.WorkItemManager.UI.SystemContext.Current.DataPortal.WorkItemWorkConditionManager.SaveItemAsync(this, mode);
        }
        public async System.Threading.Tasks.Task<WorkItemWorkCondition> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.WorkItemManager.UI.SystemContext.Current.DataPortal.WorkItemWorkConditionManager.SaveItemAsync(this, settings);
        }
        public async System.Threading.Tasks.Task<WorkItemWorkCondition> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.WorkItemManager.UI.SystemContext.Current.DataPortal.WorkItemWorkConditionManager.SaveItemAsync(this, settings, strategyContext, objectParameters);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.ValidateAsync(this, context);
            await ValidateAsync(context);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync();
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemWorkConditionManager.Initialize(this, settings);
        }

        #endregion
        
        #region IWorkItemWorkCondition Members

        string global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.ConditionContext
        {
            get
            {
                return this._ConditionContext;
            }
            set
            {
                this._ConditionContext = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.GroupId
        {
            get
            {
                return this._GroupId;
            }
            set
            {
                this._GroupId = value;
            }
        }
        global::Sidvall.WorkItemManager.Workflow.ThreadAction global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.InvalidAction
        {
            get
            {
                return this._InvalidAction;
            }
            set
            {
                this._InvalidAction = value;
            }
        }
        bool global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.IsEnabled
        {
            get
            {
                return this._IsEnabled;
            }
            set
            {
                this._IsEnabled = value;
            }
        }
        bool global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.IsEnabledOnRetry
        {
            get
            {
                return this._IsEnabledOnRetry;
            }
            set
            {
                this._IsEnabledOnRetry = value;
            }
        }
        long global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.WorkConditionId
        {
            get
            {
                return this._WorkConditionId;
            }
            set
            {
                this._WorkConditionId = value;
            }
        }
        long global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.WorkItemId
        {
            get
            {
                return this._WorkItemId;
            }
            set
            {
                this._WorkItemId = value;
            }
        }
        global::Sidvall.WorkItemManager.Data.IWorkCondition global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.WorkCondition
        {
            get
            {
                return this._WorkCondition;
            }
            set
            {
                UpdateChildProperty(this._WorkCondition, value);
                this._WorkCondition = value as WorkCondition;
            }
        }
        global::Sidvall.WorkItemManager.Data.IWorkItem global::Sidvall.WorkItemManager.Data.IWorkItemWorkCondition.WorkItem
        {
            get
            {
                return this._WorkItem;
            }
            set
            {
                UpdateChildProperty(this._WorkItem, value);
                this._WorkItem = value as WorkItem;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public WorkItemWorkCondition()
        {
        }

        public WorkItemWorkCondition(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}